package com.gitee.faster.webdav.kernel.protocol.dispatcher;

import com.gitee.faster.webdav.common.constant.MethodEnum;
import com.gitee.faster.webdav.kernel.protocol.HttpExchange;
import com.gitee.faster.webdav.kernel.resource.Resource;
import com.gitee.faster.webdav.kernel.resource.ResourceRepository;
import lombok.extern.slf4j.Slf4j;
import org.smartboot.http.common.enums.HttpStatus;

/**
 * @author hongda.li
 */
@Slf4j
public class MethodDispatcherDelete implements MethodDispatcher {
    @Override
    public MethodEnum supported() {
        return MethodEnum.DELETE;
    }

    @Override
    public void dispatch(HttpExchange accessor) {
        Resource resource = accessor.getResource();
        ResourceRepository repository = accessor.getRepository();
        log.info("删除文件或目录 : {}", resource.getName());
        repository.delete(resource);
        accessor.setHttpStatus(HttpStatus.OK);
    }
}
